<?php
//引入初始化文件
include '../init.php';
//引入数据库文件
include DIR_CORE . 'mysql.php';

$title = '沐水莲心-单选题';

// 判断用户是否登录
login();

$type = $_POST['type'];
$star = $_POST['star'];
$end = $_POST['end'];
$keywords = $_POST['keywords'];
$jump = $_POST['jump'];

//var_dump($_POST);
if (!empty($type)) {
    $where = "where type_id ='$type'";
    $_SESSION['where'] = $where;
}
if (!empty($type)&&!empty($star)&&!empty($end)) {
    $where = "where type_id = '$type' and id between '$star' and '$end'";
    $_SESSION['where'] = $where;
}
if (!empty($keywords)) {
    $where = "where question like '%$keywords%'";
    $_SESSION['where'] = $where;
}
if (!empty($jump)) {
    $where = "where id = '$jump'";
    $_SESSION['where'] = $where;
}
//var_dump($_SESSION['where']);

//取题目类型
$tsql = "select * from type";
$tres = mysqli_query($link, $tsql);
$tlist = array();
while ($row = mysqli_fetch_assoc($tres)) {
    $tlist[]=$row;
}
//var_dump($tlist);

//提取single表总的数据信息
$ssql = "select count(*) as sum from single {$_SESSION['where']}";
$sres = mysqli_query($link, $ssql);
$srow = mysqli_fetch_assoc($sres);
//var_dump($srow);

$rowCount = $srow['sum'];

// 得到总记录数

if ($rowCount != 0) {
    $config =
    include DIR_CONFIG . 'config.php';
    $rowsPerPage = $config['pages']['rowsPerPage'];
    $url = "single_deal.php";
    
    //载入分页文件
    include DIR_CORE . 'pages.php';

    $strPage = page($rowCount, $maxnum, $rowsPerPage, $url);

    $pageNum = isset($_GET['pageNum']) ? $_GET['pageNum'] : 1;

    //提取single表的数据
    $offset = ($pageNum - 1) * $rowsPerPage;
    ;
    $sql = "select * from single {$_SESSION['where']} limit $offset, $rowsPerPage";
    //echo $sql;
    $res = mysqli_query($link, $sql);
    // 得到资源结果集,
    
    //定义空数组存数据
    $list = array();
    //遍历数据库，取数据
    while ($row = mysqli_fetch_assoc($res)) {
        $list[]=$row;
    }
    //var_dump($list);
    //引入视图文件
    include DIR_VIEW .'singleForm.html';
} else {
    jump('single.php', '此类型无题目');
}
